package com.arm.tools.result;


import com.arm.tools.json.JsonHandler;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@ApiModel(value = "反馈对象", description = "反馈对象")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultObj<T> {
    /**
     * 反馈状态
     */
    @ApiModelProperty(value = "状态码（0：失败，1：成功，其他为错误码）", name = "code", example = "1", dataType = "int", required = true)
    private Integer code;

    /**
     * 反馈信息
     */
    @ApiModelProperty(value = "反馈信息", name = "msg", example = "成功", dataType = "string", required = true)
    private String msg;

    /**
     * 反馈数据
     */
    @ApiModelProperty(value = "反馈数据", name = "data", example = "", dataType = "T", required = true)
    private T data;



    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ResultObj() {
        super();
        this.code=ReturnCode.SUCCESS.getCode();
        this.msg=ReturnCode.SUCCESS.getMsg();
        // TODO Auto-generated constructor stub
    }

    public ResultObj(ReturnCode returnCode) {
        this.code = returnCode.getCode();
        this.msg = returnCode.getMsg();
    }
    public ResultObj(ReturnCode returnCode, T data) {
        this.code = returnCode.getCode();
        this.msg = returnCode.getMsg();
        this.data = data;
    }

    public ResultObj(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    public String toJson() {
        return JsonHandler.objectToJson(this);
    }




    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
    
    public static void main(String[] args) {
    	List<Map> li = new ArrayList<Map>();
		Map map = new HashMap();
		map.put("asdf", 1234);
		map.put("55", 1234);
		map.put("tt", 1234);
		Map map1 = new HashMap();
		li.add(map);
		map1.put("list", li);
		//System.out.println(new ResultObj(1, "成功", map1).toJson());
	}
}
